from google.appengine.ext import db


class Information(db.Model):
    name = db.StringProperty(required=True)
    secret = db.StringProperty(required=True)
    timestamp = db.DateTimeProperty(auto_now_add=True)
    usage = db.IntegerProperty(default=0)
 
class NumberImage(db.Model):
    information = db.ReferenceProperty(Information)
    img0 = db.BlobProperty()    
    img1 = db.BlobProperty()
    img2 = db.BlobProperty()
    img3 = db.BlobProperty()
    img4 = db.BlobProperty()
    img5 = db.BlobProperty()
    img6 = db.BlobProperty()
    img7 = db.BlobProperty()
    img8 = db.BlobProperty()
    img9 = db.BlobProperty()
    
    @staticmethod
    def queryByInfoKey(key):
        try:
            info = db.get(key)
            if info:
                query = db.Query(NumberImage)
                query.filter('information =', info)
                image = query.get()
                return image
            else:
                return None
        except:
            return None